using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class SceneRaycastComponent : Button
{
    private float detectionDistance = 20f;
    public override void OnPointerClick(PointerEventData eventData)
    {
        if (eventData.button == PointerEventData.InputButton.Left)
        {
            Vector2 v2 = eventData.position;
            Ray ray = Camera.main.ScreenPointToRay(v2);
            RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, detectionDistance);
            if (hit.collider != null)
            {
                object dectionObj = hit.collider.gameObject;
                object dectionPos = hit.point;
                PublicEventCenter.Dispatch(UIManager.ClickSceneGameObjectEvent, new object[] { dectionObj, dectionPos });
            }
        }
    }
}
